%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% This file is part of the book
%%
%% Algorithmic Graph Theory
%% http://code.google.com/p/graphbook/
%%
%% Copyright (C) 2009--2013 Minh Van Nguyen <mvngu.name@gmail.com>
%%
%% See the file COPYING for copying conditions.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{algorithmic}[1]
%% input and output
\Require Positive integer $n$ and a probability $0 < p < 1$.
\Ensure A random graph from $G(n,p)$.
%%
%% algorithm body
\State $G \gets \overline{K_n}$
\State $V \gets \{0, 1, \dots, n - 1\}$
\For{$i \gets 0, 1, \dots, n - 2$}
  \For{$j \gets i + 1, i + 2, \dots, n - 1$}
    \State $r \gets$ draw uniformly at random from interval $(0,1)$
    \If{$r < p$}
      \State add edge $ij$ to $G$
    \EndIf
  \EndFor
\EndFor
\State \Return $G$
\end{algorithmic}
